package com.kabigon.tiny.controller;

import com.kabigon.tiny.anno.CurrentUser;
import com.kabigon.tiny.domain.sysuser.SysUser;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author xu.biao
 * @version v1.0
 * @Package com.kabigon.tiny.controller
 * @data 2023-07-30 15:54
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private JdbcTemplate jdbcTemplate;

    @GetMapping("getCurrentUser")
    public String getUserById(@CurrentUser SysUser sysUser) {
        return sysUser.toString();
    }

    @GetMapping("save")
    public void saveUser() {
        //jdbcTemplate.query("SELECT * FROM sys_user WHERE 1=1", (rs, rowNum) -> {
        //    Console.log("id: {}, user_name: {}", rs.getString("id"), rs.getString("user_name"));
        //    return null;
        //});
        List<Map<String, Object>> users = jdbcTemplate.queryForList("SELECT user_name, user_password FROM sys_user WHERE user_name = 'admin' OR '1'='1' UNION SELECT user_name, user_password FROM sys_user");
        //jdbcTemplate.update("UPDATE sys_user SET phone = '111' WHERE 1=1");
    }

}
